This invention relates to a compiler that generates executable software applications from source code written in a programming language. More particularly, this invention relates to a linker in a compiler that allows symbols in an intermediate object code file and/or library to be renamed without recompiling the source code for the intermediate object code file and/or library.
In order to produce executable programs for computer systems, computer programmers write source code in a programming language. Some examples of programming languages are C, C++, Fortran, Pascal, and Visual Basic. In order to convert the source code into code that can be read by a processor, the source code is input into a compiler that converts the source code into machine readable code.
It is common for the source code of a software application to be written in many different phases or in many different components. For example, several programmers may each be working on a different aspect of an application or a new feature may be added to an existing application to improve performance of the application. Different flies containing the different components of an application are joined together by a linker in a compiler while the executable code is being generated.
The linker is an editor that checks each file to make sure that the terms or symbols from the different flies agree. For purposes of the present discussion, a symbol is a name identifying any variable or function in the source code. If the symbols for a particular variable or function do not agree in multiple files of an application, the linker detects an error. When an error is detected by the linker, the linker either raises flags indicating possible mismatches or does not allow the files to be compiled into executable code. When a symbol mismatch occurs, the programmer or programmers must go back into each file of source code for the application and find the mismatched symbol. The mismatch must then be corrected and the files must each be recompiled and applied to a link editor. This is a problem because every file containing source code must be corrected and then re-compiled in order to make executable code.
Furthermore, when a file containing a new layer of is added to an application, each source file must be recompiled to assure matching symbols for each object. This is a waste of processing time to recompile unchanged code. It would instead be desirable to allow new layers of software to be added and call an existing defination without recompiling the existing code. There is a need in the art for a process performed by a linder in a compiler that reduces the acount of files that must be recompiled when a new layer of software is added to an application.
The above and other problems are solved and an advance in the art is made by the system for automatically remaning symbols in files during the compiling of the files, termed xe2x80x9csymbol remaning processxe2x80x9d herein. Symbol remaning allows a symbol in a first file or library to be remaned by the linker. This allows new layers of software to be added under an existing interface without recompiling existing code. Symbol renaming in the linker also allows a programmer to easily fix mismatched symbols in linked files without recompiling the source code in all of the linked files.
In order to convert source code into executable code, the source files containing the source code must be processed by a compiler, linker, and a constructor. Each source file is first processed by a compiler. The compiler is comprised of a scanner, a parser and a semantic checker. The scanner scans each file to detect each symbol or token in the file. The parser detects the structure of expressions in the language to detect each expression. The semantic checker determines the meaning of each symbol in an expression. The intermediate code generator than generates a file of intermediate object code for each file of source code. The intermediate object code file represents the data structures and functions defined in the source code file as determined by the semantic checker.
After all of the files of source code have been compiled into intermediate object code files, the intermediate object code files are applied to a linker which joins the files of intermediate object code into one file. The linker checks for agreements between symbols declared in each source code file. If there is an error in agreement in symbol types, the linker either flags the error and indicates the error to the programmer(s) or does not allow the files to be linked. After the files have been linked, the resulting file is applied to a constructor which generates an executable file.
The present symbol renaming process performs the symbol renaming in the linker in the following manner. The linker scans a first intermediate object code file to detect a substitution indicator indicating a variable or function in a second file is to be renamed. The symbol to be replaced is read and then the substitution symbol is read. The linker then replaces every occurrence of the symbol as the symbol is read from a second file or library with the substitution symbol in the intermediate code file generated by the linker.